let shippingOrderForm    = $('#shippingInform'),
    confirmOrderForm     = $('#confirmOrder'),
    viewOrderForm   = $('#ViewOrder');

$(function () {
    shippingOrderForm.hide();
    confirmOrderForm.hide();
    viewOrderForm.hide();

    // 初始第一个订单界面的出现，考虑用户需求是否需要将第一个页面隐藏
    $('#newOrderForm').on('submit',function (e) {
        e.preventDefault();
        let data = $('#newOrderForm').serialize();
        // console.log(data);
        $.ajax({
            type    : 'POST',
            url     : 'newOrder',
            data    : data,
            success : function (data){
                if (data === 'checked'){
                    shippingOrderForm.show();
                } else if (data === 'not checked'){
                    // 重新加载页面
                    confirmOrderForm.load(location.href + ' #confirmOrder');
                    confirmOrderForm.show();
                }
                $('#newOrderBtn').hide();
            },
            error   : function (errorMsg){
                console.log(errorMsg);
            }
        });
    });
    $('#shippingAddressForm').on('submit',function (e) {
        e.preventDefault();
        let data = $('#shippingAddressForm').serialize();
        $.ajax({
            type    : 'POST',
            url     : 'shippingForm',
            data    : data,
            success : function (data) {
                console.log(data);
                confirmOrderForm.load(location.href + ' #confirmOrder');
                confirmOrderForm.show();
            },
            error   : function (errorMsg) {
                console.log(errorMsg);
            }
        });
    });

});